package cn.wei.myblog.web.controller;

import cn.wei.common.core.controller.BaseController;
import cn.wei.common.core.domain.AjaxResult;
import cn.wei.common.core.page.TableDataInfo;
import cn.wei.myblog.domain.entity.BlogArticle;
import cn.wei.myblog.service.IBlogArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/blog/article")
public class BlogArticleController extends BaseController {

    @Autowired
    private IBlogArticleService blogArticleService;

    @GetMapping(value = "/{articleId}")
    public AjaxResult getArticleInfo (@PathVariable Long articleId) {
        return success(blogArticleService.selectArticleById(articleId));
    }

    @PostMapping(value = "/add")
    public AjaxResult addArticle (@RequestBody BlogArticle blogArticle) {
        blogArticle.setCreateBy(getUserId());
        return success(blogArticleService.insertArticle(blogArticle));
    }

    @GetMapping("/list")
    public TableDataInfo list(BlogArticle blogArticle) {
        startPage();
        List<BlogArticle> list = blogArticleService.selectArticleList(blogArticle);
        return getDataTable(list);
    }
}
